package commands

import (
	"context"
	"golang-manage-admin/queue/publish"

	"github.com/spf13/cobra"
	"golang-manage-admin/providers"
	"golang-manage-admin/queue"
)

var QueueCmd = &cobra.Command{
	Use:   "queue",
	Short: "队列监听",
	Args:  cobra.NoArgs,
	Run: func(cmd *cobra.Command, args []string) {
		defer providers.Logger.Flush()
		queueObject := queue.RabbitMqQueue()

		// 主程退出的时候：关闭其他协程
		ctx, cancel := context.WithCancel(context.Background())
		defer cancel()

		// 推送队列初始化
		publish.PublishInit()

		queueObject.Bind(ctx)

		// @TODO 保留：控制指定队列的消费者关闭
		stop := make(chan struct{})
		<-stop

	},
}
